export const deepCopy = (data:unknown) => {
    const map = new WeakMap()

    const _deepCopy = (obj:unknown) => {
        if(obj == null || typeof obj !== 'object')
            return obj
        if(map.has(obj))
            return map.get(obj)
        const result:Record<string,any> = Array.isArray(obj)?[]:{}
        map.set(obj, result)
        for (let key in obj) {
            if(obj.hasOwnProperty(key)) {
                result[key] = _deepCopy((obj as Record<string, any>)[key])
            }
        }

        return result
    }

    return _deepCopy(data)
}